{% extends '@Admin/adminFramework/example/list.html.twig' %}
{% import "@Admin/adminFramework/loader/model.loader.twig" as loader_model %}
{% import "@Admin/adminFramework/loader/base.loader.twig" as loader_base %}
{% import "@Admin/adminFramework/loader/control.loader.twig" as loader_control %}
{% block input %}
    {{ loader_control.label('分类名称：')|raw }}
    {{ loader_control.text(app.request.get('article_class_name')|default(''), '请输入分类名称', 'text', 'input_article_class_name', ' name="article_class_name" ') }}

    {{ loader_control.label('是否首页推荐：') }}
    {{ loader_control.select(app.request.get('is_recommend')|default('-1'), is_true_arr, ' name = "is_recommend" id="select_is_recommend" ', "-1", '请选择是否首页推荐') | raw }}
{% endblock %}

{% block action %}
    {{ loader_control.a('添加', 'button', 'btn btn-success btn-add', ' href="editPage" ') | raw }}
{% endblock %}

{% block th %}
    <th style="width:50px;">序号</th>
    <th style="width:100px;">分类名称</th>
    <th style="width:300px">是否首页推荐</th>
    <th style="width:100px">操作</th>
{% endblock %}

{% block before %}
    {{ loader_model.load_navigation('文章分类', '文章管理', { '文章分类列表':'' }) }}
{% endblock %}

{% block title %}文章列表{% endblock %}

{% block td %}
    <td>{{ (app.request.get('page', 1) - 1) * app.request.get('rows', 15) + item + 1 }}</td>
    <td>{{ value.article_class_name|default }}</td>
    <td>{{ value.is_recommend_str|default }}</td>
    <td>
        {{ loader_control.a('编辑','','btn btn-info btn-update','href ="' ~path('admin_article_class_editPage',{'id':value.id})~ '"') }}
        {{ loader_control.buttonDelete('删除', 'data-id="' ~value.id~ '"', 'btn-delete-article-class') }}
        {% if value.is_recommend == 0 %}
            {{ loader_control.buttonEdit('设置推荐',' id="set-recommend" data-id ="'~value.id~'" data-is_recommend ="1" ','edit-recommend') }}
        {% else %}
            {{ loader_control.buttonDelete('取消推荐',' id="cancel-recommend" data-id ="'~value.id~'" data-is_recommend ="0" ','edit-recommend') }}
        {% endif %}
    </td>
{% endblock %}

{% block jquery %}
{{ parent() }}
    <script>
        //删除文章分类
        $('.btn-delete-article-class').click(function () {
            var id = $(this).data('id');
            windowsConfirm('是否确认删除？', function () {
                $.post("{{ path('admin_article_class_delete') }}", {'id':id}, function (result) {
                    resultPreprocess(result, '');
                })
            });
        });

        //是否推荐编辑
        $('.edit-recommend').click(function () {
            var id = $(this).data('id');
            var is_recommend = $(this).data('is_recommend');
            $.post('{{ path('admin_article_class_editIsRecommend') }}',{'article_class_id':id,'is_recommend':is_recommend},function (result) {
                resultPreprocess(result,'');
            })
        });
    </script>
{% endblock %}

{% block click_btn_clear %}
    $('input').val('');
    $('#input-rows').val(15);
    $('#select_is_recommend').val('-1');
{% endblock %}